<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined( '_JEXEC' ) or die( 'Restricted access' );

class iJoomla_SurveysControllerResponses extends iJoomla_SurveysController{
	function __construct() {	  
		parent::__construct();
		// Register Extra tasks		
		$this->registerTask('', 'responses');
		$this->registerTask('publish', 'publish_unpublish');
		$this->registerTask('unpublish', 'publish_unpublish');
		$this->registerTask('clear', 'clear');		
		$this->registerTask('cancel', 'cancel');
	}
	
	function responses(){
		JRequest::setVar( 'view', 'Responses' );	
		parent::display();
	}
	
	function publish_unpublish(){
		$model = $this->getModel('responses');
		$response = $model->publish_unpublish();		
		$link = "index.php?option=com_surveys&controller=responses&id=".JRequest::getVar("id", "0");
		$task = JRequest::getVar("task", "");
		
		if($task == "publish"){
			if ($response === false) {
				$msg = JText::_("COM_SURVEYS_PUBLISH_UNSUCCESSFULLY");
				$this->setRedirect($link, $msg, 'notice');
			} 
			elseif($response === true) {
				$msg = JText::_("COM_SURVEYS_PUBLISH_SUCCESSFULLY");		
				$this->setRedirect($link, $msg);
			}
		}
		else{
			if ($response === false) {
				$msg = JText::_("COM_SURVEYS_UNPUBLISH_UNSUCCESSFULLY");
				$this->setRedirect($link, $msg, 'notice');
			} 
			elseif($response === true) {
				$msg = JText::_("COM_SURVEYS_UNPUBLISH_SUCCESSFULLY");		
				$this->setRedirect($link, $msg);
			}
		}
	}
	
	function clear(){
		$model = $this->getModel('responses');
		$response = $model->clear();		
		$link = "index.php?option=com_surveys&controller=responses&id=".JRequest::getVar("id", "0");
		if ($response === false) {
			$msg = JText::_("COM_SURVEYS_DELETE_RES_UNSUCCESSFULLY");
			$this->setRedirect($link, $msg, 'notice');
		} 
		elseif($response === true) {
			$msg = JText::_("COM_SURVEYS_DELETE_RES_SUCCESSFULLY");		
			$this->setRedirect($link, $msg);
		}
	}
	
	function cancel(){
		$link = "index.php?option=com_surveys&controller=surveys";
		$this->setRedirect($link);
	}
};

?>